package com.yan.mem.controller;

import com.yan.mem.dao.UserMapper;
import com.yan.mem.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {
    private final UserMapper userMapper;

    public UserController(@Autowired(required = false) UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @GetMapping("getAllUser")
    public List<User> getAllUser() {
        return userMapper.getAllUser();
    }

    @GetMapping("getById")
    public User getById(int id) {
        return userMapper.getById(id);
    }

    @PostMapping("addUser")
    public boolean addUser(@RequestBody User user) {
        return userMapper.addUser(user);
    }

    @PostMapping("delById")
    public boolean delById(int id) {
        return userMapper.delById(id);
    }
}
